package com.example.t470p.facechecktickets.DynamicFaceMatch;

import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Point;
import android.os.Build;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Display;
import android.view.WindowManager;

public class MeasureUtil {

	private static final String TAG = "MeasureUtil";

	public static int[] getScreenSize(Context activity) {
		// ��ȡ��Ļ�ܶȣ�����2��
		DisplayMetrics dm = new DisplayMetrics();
		Log.d(TAG, "activity" + activity);
		dm = activity.getResources().getDisplayMetrics();
		float density = dm.density; // ��Ļ�ܶȣ����ر�����0.75/1.0/1.5/2.0��
		int densityDPI = dm.densityDpi; // ��Ļ�ܶȣ�ÿ�����أ�120/160/240/320��
		float xdpi = dm.xdpi;
		float ydpi = dm.ydpi;
		int screenWidth = dm.widthPixels; // ��Ļ�����أ��磺480px��
		int screenHeight = dm.heightPixels; // ��Ļ�ߣ����أ��磺800px��
		int[] screens = { screenWidth, screenHeight };
		return screens;
	}

	/**
	 *
	 * @param context ������
	 * @param dpValue dp��ֵ
	 * @return dp to  px
	 */
	public static int dip2px(Context context, float dpValue) {
		final float scale = context.getResources().getDisplayMetrics().density;
		return (int) (dpValue * scale + 0.5f);

	}
	/**
	 * ��ȡ��Ļ�ߴ�
	 */
	@SuppressWarnings("deprecation")
	@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
	public static Point getScreenPoint(Context context){
		WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
		Display display = windowManager.getDefaultDisplay();
		if(Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR2){
			return new Point(display.getWidth(), display.getHeight());
		}else{
			Point point = new Point();
			display.getSize(point);
			return point;
		}
	}
	/**
	 *
	 * @param context    ������
	 * @param pxValue  px����ֵ
	 * @return  px to dp
	 */
	public static int px2dip(Context context, float pxValue) {
		final float scale = context.getResources().getDisplayMetrics().density;
		return (int) (pxValue / scale + 0.5f);

	}

}
